package com.itheima.web.controller;

import com.itheima.pojo.Product;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-13 11:44
 * @description
 */
@Controller
@RequestMapping("/products")
@ResponseBody
public class demo3_ProductController {

    /***
     * 添加一个商品数据
     * method:请求方式 必须是post类型
     */
    @RequestMapping(value = "",method = RequestMethod.POST)
    public String add(Product product){
        System.out.println("添加一个商品:"+product);
        return "success";
    }

    /**
     * 路径参数
     * PathVariable
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public String del(@PathVariable("id") int id ){
        System.out.println("正在删除:"+id+"的商品");
        return "success";
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public String update(@PathVariable("id") int id,@RequestBody Product product ){
        System.out.println("正在更新:"+id+"的商品"+"----"+product);
        return "success";
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public String findById(@PathVariable("id") int id ){
        System.out.println("正在获取:"+id+"的商品");
        return "success";
    }




}
